package com.example.wechat;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

@Dao
public interface MessageDao {
    @Insert
    long insert(Message message);

    @Update
    void update(Message message);

    @Query("SELECT * FROM messages WHERE conversationId = :conversationId ORDER BY timestamp ASC")
    LiveData<List<Message>> getMessagesByConversation(String conversationId);

    @Query("SELECT * FROM messages WHERE id = :messageId")
    Message getMessageById(long messageId);

    @Query("UPDATE messages SET status = :status WHERE id = :messageId")
    void updateMessageStatus(long messageId, int status);

    @Query("SELECT COUNT(*) FROM messages WHERE conversationId = :conversationId AND status = 0")
    int getUnreadMessageCount(String conversationId);
} 